set more off
clear all
set matsize 5000

* file path here
cd ""


*****************
* main analysis *
*****************

use data_cross, clear

* Table 1 *

eststo clear
eststo: xi: quietly reg st_cum1 mirk marketcap, r
eststo: xi: quietly reg ab_cum1 mirk marketcap, r

eststo: xi: quietly reg st_cum2 mirk marketcap, r
eststo: xi: quietly reg ab_cum2 mirk marketcap, r

esttab using table_reg_cross_tmp.tex, ///
	replace label nomtitles fragment booktabs ///
	stats(N r2, fmt(%7.0fc %5.3f) labels("N" "\$R^2$")) ///
	star(* 0.1 ** 0.05 *** 0.01) nodepvar nonote b(%5.4f) se(%5.4f) ///
	keep  (mirk marketcap) ///
order (mirk marketcap)

quietly {

	capture log close
  
	log using "table_reg_cross.tex", text replace

	
	noisily display "\begin{table}[htbp]"
	noisily display "\centering"
    noisily display "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"		
	noisily display "\begin{threeparttable}"
	noisily display "\caption{Stock Market's Response to the Impeachment of President Park}"
	noisily display "\label{table_reg_cross}"
	noisily display "\begin{tabular}{lcccc}"
	noisily display "\midrule\midrule"
	noisily display "&\multicolumn{2}{c}{Event 1}&\multicolumn{2}{c}{Event 2}\\"
	noisily display "\cmidrule(r){2-3}\cmidrule(r){4-5}"
	noisily display "&\multicolumn{2}{c}{Cumulative}&\multicolumn{2}{c}{Cumulative}\\"	
	noisily display "&\multicolumn{1}{c}{Stock}&\multicolumn{1}{c}{Abnormal}&\multicolumn{1}{c}{Stock}&\multicolumn{1}{c}{Abnormal}\\"
	noisily display "&\multicolumn{1}{c}{Return}&\multicolumn{1}{c}{Stock Return}&\multicolumn{1}{c}{Return}&\multicolumn{1}{c}{Stock Return}\\"	
	noisily display "\cmidrule(r){2-2}\cmidrule(r){3-3}\cmidrule(r){4-4}\cmidrule(r){5-5}"
	noisily display "\input{table_reg_cross_tmp.tex}"
	noisily display "\midrule\midrule"
	noisily display "\end{tabular}"
	noisily display "\begin{tablenotes}"
	noisily display "\footnotesize"
	noisily display "\item \textit{Notes}: Robust standard errors are in parentheses."
	noisily display "Event 1: The passing of the impeachment bill in the National Assembly."
	noisily display "Event 2: The ruling by the Constitutional Court."
	noisily display "\item *** \$p<0.01$; ** \$p<0.05\$; * \$p<0.1\$."
	noisily display "\end{tablenotes}"
	noisily display "\end{threeparttable}"
	noisily display "\end{table}"
  
	log off
  
	log close
}

* summary statistics (Table A.1.) * 

eststo clear
eststo: quietly estpost sum mirk marketcap st_cum1 ab_cum1 st_cum2 ab_cum2 

esttab using "table_sum_tmp.tex",  ///
  replace label cells("mean(fmt(%5.3f)) sd min max count(fmt(%6.0fc))") ///
  noobs booktabs nomtitles fragment nonumbers alignment(rrrcc) ///
  collabels("{Mean}" "{Std Dev}" "{Min}" "{Max}" "{N}")
  
quietly {

	capture log close
  
	log using "table_sum.tex", text replace

 	noisily display "\begin{table}[htbp]"
	noisily display "\centering"
	noisily display "\begin{threeparttable}"
	noisily display "\caption{Summary Statistics} \label{table_sum}"
	noisily display "\begin{tabular}{l*{4}{S}c}"
	noisily display "\midrule\midrule"
	noisily display "\input{table_sum_tmp.tex}"
	noisily display "\midrule\midrule"
	noisily display "\end{tabular}"
	noisily display "\begin{tablenotes}"
	noisily display "\footnotesize"	
	noisily display "\item \textit{Notes}: Event 1: The passing of the impeachment bill in the National Assembly."
	noisily display "Event 2: The ruling by the Constitutional Court."
	noisily display "\end{tablenotes}"
	noisily display "\end{threeparttable}"
	noisily display "\end{table}"
  
	log off

	log close
  
}

* figure 2 *

use data_panel, clear

replace mirk = 1 if mirk == 2

gen beta   = .
gen se     = .
gen beta_l = .
gen beta_u = .
gen tstat  = .

quietly sum time

forvalues i = 2/`r(max)' {
	reg ab_return mirk if time == `i', r
	replace beta = _b[mirk] if time == `i'
	replace se  = _se[mirk] if time == `i'
	replace tstat = _b[mirk] / _se[mirk] if time == `i'
	replace beta_l = _b[mirk] - 1.96 * _se[mirk] if time == `i'
	replace beta_u = _b[mirk] + 1.96 * _se[mirk] if time == `i'
}
compress
keep date_str date time beta se tstat beta_l beta_u
duplicates drop
compress

gen x = string(date, "%dMon_dd")

labmask time, value(x)

gen event1 = time if date>=date("2016/12/09","YMD") & date<=date("2016/12/12","YMD")
gen event2 = time if date>=date("2017/03/10","YMD") & date<=date("2017/03/13","YMD")


forvalues i = 1/2 {

	quietly sum event`i'

	local min  = r(min) - 3
	local max  = r(max) + 3
	local min1 = r(min) - 4
	local max1 = r(max) + 4

	twoway (rcap beta_l beta_u time)    ///
	   (scatter beta time, msymbol(S) msize(medium)) ///
	   if time >= `min' & time <= `max', /// 
	   scheme(burd) legend(off) yline(0, lpattern(solid))   ///
	   xscale(range(`min1' `max1')) xlabel(`min1' (2) `max', valuelabel) ///
	   xtitle("Date") ytitle("")

	graph export figure_reg`i'.eps, replace

}


*********************
* Robustness checks *
*********************

* panel data analysis (Table A.2.)  *

use data_panel, clear

drop if date>date("2017/03/13","YMD")

eststo clear
eststo: xi: quietly areg st_return kospi_return mirk event1 event2 event1Xmirk event2Xmirk, a(company) cluster(company)
eststo: xi: quietly areg st_return kospi_return mirk event1 event2 event1Xmirk event2Xmirk marketcap event1Xmarketcap event2Xmarketcap, a(company) cluster(company)
eststo: xi: quietly areg ab_return event1 event2 mirk event1Xmirk event2Xmirk, a(company) cluster(company)
eststo: xi: quietly areg ab_return event1 event2 mirk event1Xmirk event2Xmirk event1Xmarketcap event2Xmarketcap, a(company) cluster(company)

esttab using table_reg_panel_tmp.tex, ///
	replace label nomtitles fragment booktabs ///
	stats(N r2, fmt(%7.0fc %5.3f) labels("N" "\$R^2$")) ///
	star(* 0.1 ** 0.05 *** 0.01) nodepvar nonote b(%5.3f) se(%5.3f) ///
	keep(kospi_return event1 event2 event1Xmirk event2Xmirk event1Xmirk event2Xmirk event1Xmarketcap event2Xmarketcap) ///
order(kospi_return event1 event2 event1Xmirk event2Xmirk event1Xmirk event2Xmirk event1Xmarketcap event2Xmarketcap)


quietly {

	capture log close
  
	log using table_reg_panel.tex, text replace

	
	noisily display "\begin{table}[htbp]"
	noisily display "\centering"
    noisily display "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"		
	noisily display "\begin{threeparttable}"
	noisily display "\caption{Stock Market's Response to the Impeachment of President Park (Alternative Specification)}"
	noisily display "\label{table_reg_panel}"
	noisily display "\begin{tabular}{lcccc}"
	noisily display "\midrule\midrule"
	noisily display "&\multicolumn{4}{c}{Dependent Variable}\\"
	noisily display "\cmidrule(r){2-5}"
	noisily display "&\multicolumn{4}{c}{Cumulative}\\"	
	noisily display "&\multicolumn{2}{c}{Stock}&\multicolumn{2}{c}{Abnormal}\\"
	noisily display "&\multicolumn{2}{c}{Return}&\multicolumn{2}{c}{Stock Return}\\"
	noisily display "\cmidrule(r){2-3}\cmidrule(r){4-5}"
	noisily display "\input{table_reg_panel_tmp.tex}"
	noisily display "\midrule\midrule"
	noisily display "\end{tabular}"
	noisily display "\begin{tablenotes}"
	noisily display "\footnotesize"
	noisily display "\item \textit{Notes}: Standard errors in parentheses are clustered by firm. Firm fixed effects"
	noisily display "are included in all columns."
	noisily display "Event 1: The passing of the impeachment bill in the National Assembly."
	noisily display "Event 2: The ruling by the Constitutional Court."
	noisily display "\item *** \$p<0.01$; ** \$p<0.05\$; * \$p<0.1\$."
	noisily display "\end{tablenotes}"
	noisily display "\end{threeparttable}"
	noisily display "\end{table}"
  
	log off
  
	log close
}


* Without parent companies (Table A.3.) *

use data_cross, clear

eststo clear
eststo: xi: quietly reg st_cum1 mirk marketcap if parent != 1, r
eststo: xi: quietly reg ab_cum1 mirk marketcap if parent != 1, r

eststo: xi: quietly reg st_cum2 mirk marketcap if parent != 1, r
eststo: xi: quietly reg ab_cum2 mirk marketcap if parent != 1, r

esttab using table_reg_cross_robust_tmp.tex, ///
	replace label nomtitles fragment booktabs ///
	stats(N r2, fmt(%7.0fc %5.3f) labels("N" "\$R^2$")) ///
	star(* 0.1 ** 0.05 *** 0.01) nodepvar nonote b(%5.4f) se(%5.4f) ///
	keep  (mirk marketcap) ///
order (mirk marketcap)


forvalues i = 1/4 {
	quietly `reg`i''
	foreach x in mirk marketcap {
		capture local beta_`x'`i' =  _b[`x']
		capture local se_`x'`i'   = _se[`x']
	}
	local r2_`i' = e(r2)
	local N_`i'  = e(N)
	
}

label var marketcap "Market Cap"

quietly {

	capture log close
  
	log using table_reg_cross_robust.tex, text replace

	
	noisily display "\begin{table}[htbp]"
	noisily display "\centering"
    noisily display "\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}"		
	
	noisily display "\begin{threeparttable}"
	noisily display "\caption{Stock Market Response to the Impeachment of President Park (Without Parent Companies)}"
	noisily display "\label{table_reg_cross_robust}"
	noisily display "\begin{tabular}{lcccc}"
	noisily display "\midrule\midrule"
	noisily display "&\multicolumn{2}{c}{Event 1}&\multicolumn{2}{c}{Event 2}\\"
	noisily display "\cmidrule(r){2-3}\cmidrule(r){4-5}"
	noisily display "&\multicolumn{2}{c}{Cumulative}&\multicolumn{2}{c}{Cumulative}\\"	
	noisily display "&\multicolumn{1}{c}{Stock}&\multicolumn{1}{c}{Abnormal}&\multicolumn{1}{c}{Stock}&\multicolumn{1}{c}{Abnormal}\\"
	noisily display "&\multicolumn{1}{c}{Return}&\multicolumn{1}{c}{Stock Return}&\multicolumn{1}{c}{Return}&\multicolumn{1}{c}{Stock Return}\\"	
	noisily display "\cmidrule(r){2-2}\cmidrule(r){3-3}\cmidrule(r){4-4}\cmidrule(r){5-5}"
	noisily display "\input{table_reg_cross_robust_tmp.tex}"
	noisily display "\midrule\midrule"
	noisily display "\end{tabular}"
	noisily display "\begin{tablenotes}"
	noisily display "\footnotesize"
	noisily display "\item \textit{Notes}: Robust standard errors are in parentheses."
	noisily display "This table repeats the analyses reported in Table \ref{table_reg_cross}"
	noisily display "after dropping all the parent companies."
	noisily display "Event 1: The passing of the impeachment bill in the National Assembly."
	noisily display "Event 2: The ruling by the Constitutional Court."
	noisily display "\item *** \$p<0.01$; ** \$p<0.05\$; * \$p<0.1\$."
	noisily display "\end{tablenotes}"
	noisily display "\end{threeparttable}"
	noisily display "\end{table}"
  
	log off
  
	log close
}

* Drop parent companies one at a time (Figure A.1.) *

use data_cross, clear
local parent_companies "CJ LS GS 현대차 KT LG SK 대림 신세계 금호아시아나 한진 두산 롯데 삼성 아모레퍼시픽 현대산업 포스코 한진중공업 현대백화점 한화 현대중공업 현대"

forvalues i = 1/2 {
	gen beta`i'   = .
	gen se`i'     = .
	gen beta_l`i' = .
	gen beta_u`i' = .
}
	
foreach x of local parent_companies {
	
	forvalues i = 1/2 {
		reg ab_cum`i' mirk c.marketcap#c.marketcap if parent_company != "`x'", r
		replace beta`i' = _b[mirk]  if parent_company == "`x'"
		replace se`i'   = _se[mirk] if parent_company == "`x'"
		replace beta_l`i' = _b[mirk] - 1.96 * _se[mirk] if parent_company == "`x'"
		replace beta_u`i' = _b[mirk] + 1.96 * _se[mirk] if parent_company == "`x'"
	}
		
}

keep parent_company* beta* se*
duplicates drop
drop if parent_company == ""

sort parent_company_eng 
gen id=_n
labmask id, values(parent_company_eng)

quietly sum id
local num_id = `r(max)'


twoway (scatter id beta1,   msymbol(Oh) msize(medium) mcolor(blue))    ///
	   (rcap beta_l1 beta_u1 id, horizontal lcolor(blue)),                ///	 
	   scheme(burd) xline(0, lpattern(solid) lcolor(red))      ///    
	   ylabel(1 (1) `num_id', valuelabel) ytitle("") ymtick(none) legend(off) ///
	   xscale(range(-0.02 0.01)) xlabel(-0.02 (0.01) 0.01) xtitle("Estimates")

graph export "figure_robust1.eps", replace
    
twoway (scatter id beta2,   msymbol(Oh) msize(medium) mcolor(blue))    ///
	   (rcap beta_l2 beta_u2 id, horizontal lcolor(blue)),                ///	 
	   scheme(burd) xline(0, lpattern(solid) lcolor(red))      ///    
	   ylabel(1 (1) `num_id', valuelabel) ytitle("") ymtick(none) legend(off) ///
	   xscale(range(-0.02 0.01)) xlabel(-0.02 (0.01) 0.01) xtitle("Estimates")

graph export "figure_robust2.eps", replace
 	  	

		
